//电机霍尔
#include "MotorHall.h"
#include "tim.h"
#include "SimpleFOC.h"
uint8_t hall_state=0;
void MotorHall_Enable()
{
	  __HAL_TIM_ENABLE_IT(&htim4,TIM_IT_TRIGGER);   //启动中断
    HAL_TIMEx_HallSensor_Start(&htim4);
}
void MotorHall_Disable()
{
	__HAL_TIM_DISABLE_IT(&htim4,TIM_IT_TRIGGER);
	HAL_TIMEx_HallSensor_Stop(&htim4);
}
//获取霍尔状态
uint8_t Get_Hall_State()
{
	uint8_t state=0;
	if(HAL_GPIO_ReadPin(H_C_GPIO_Port,H_C_Pin)!=GPIO_PIN_RESET)
	{
		state|=0x01U<<0;
	}
	if(HAL_GPIO_ReadPin(H_B_GPIO_Port,H_B_Pin)!=GPIO_PIN_RESET)
	{
		state|=0x01U<<1;
	}
	if(HAL_GPIO_ReadPin(H_A_GPIO_Port,H_A_Pin)!=GPIO_PIN_RESET)
	{
		state|=0x01U<<2;
	}
	return state;
}
//中断回调
void HAL_TIM_TriggerCallback(TIM_HandleTypeDef *htim)
{
	if(htim==&htim4)
	{
		hall_state=Get_Hall_State();
		UserHall_update(hall_state);
	}
}
